#pragma strict
import System.Collections.Generic;
@script AddComponentMenu("Level4/Misc/KeepAlive")
//////////////////////////////////////////////////////
///载入不同场景时,不销毁此实例.销毁掉新创建的实例.
//////////////////////////////////////////////////////
public var id:String = "1";
private static var dict:Dictionary.<String,GameObject> = new Dictionary.<String,GameObject>();

public var activeChildrenWhenAwake:boolean = true;

function Awake(){
	if(dict.ContainsKey(id)){
		Destroy(gameObject);
	}else{
		dict.Add(id,gameObject);
		DontDestroyOnLoad(gameObject);
	}
}

function OnDestroy(){
	if(dict.ContainsKey(id) && dict[id] == gameObject){
		dict.Remove(id);
	}
}

function ToString(){
	var sb:StringBuilder = new StringBuilder();
	for(var key:String in dict.Keys){
		sb.Append(key).Append(dict[key].GetInstanceID());
	}
	return sb.ToString();
}